<template>
  <div class="shop-register-container">
    <div class="register-wrapper">
      <a-card class="register-card">
        <div class="register-header">
          <div class="register-icon">
            <icon-shop class="icon" />
          </div>
          <h2 class="register-title">创建店铺</h2>
          <p class="register-subtitle">请填写您的店铺信息</p>
        </div>

        <a-form ref="registerFormRef" :model="registerForm" :rules="formRules" class="register-form">
          <div class="required-hint">
            <span class="required-star">*</span> 号为必填项
          </div>

          <div class="input-section">
            <div class="input-label">
              <icon-home />
              <span>店铺名称 <span class="required-star">*</span></span>
            </div>
            <a-form-item field="name" hide-label>
              <a-input v-model="registerForm.name" placeholder="请输入店铺名称" size="large" allow-clear />
            </a-form-item>
          </div>

          <div class="input-section">
            <div class="input-label">
              <icon-mobile />
              <span>联系电话 <span class="required-star">*</span></span>
            </div>
            <a-form-item field="contactNumber" hide-label>
              <a-input v-model="registerForm.contactNumber" placeholder="请输入店铺联系电话" size="large" :max-length="11" allow-clear />
            </a-form-item>
          </div>

          <div class="input-section">
            <div class="input-label">
              <icon-bank-card />
              <span>银行卡号 <span class="required-star">*</span></span>
            </div>
            <a-form-item field="bankAccount" hide-label>
              <a-input v-model="registerForm.bankAccount" placeholder="请输入店铺银行卡号" size="large" allow-clear />
            </a-form-item>
          </div>

          <div class="input-section">
            <div class="input-label">
              <icon-edit />
              <span>店铺描述</span>
            </div>
            <a-form-item field="description" hide-label>
              <a-textarea v-model="registerForm.description" placeholder="请输入店铺描述（可选）" size="large" :max-length="200" show-word-limit allow-clear />
            </a-form-item>
          </div>



          <div class="button-section">
            <a-button type="primary" size="large" :loading="loading" :disabled="loading"
              @click="handleRegister" class="register-button">
              <template #icon>
                <icon-check-circle />
              </template>
              完成注册
            </a-button>
          </div>
        </a-form>
      </a-card>

      <div class="register-decoration">
        <div class="decoration-circle circle-1"></div>
        <div class="decoration-circle circle-2"></div>
        <div class="decoration-circle circle-3"></div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { Message } from '@arco-design/web-vue'

const router = useRouter()
const registerFormRef = ref()
const loading = ref(false)

const registerForm = reactive({
  name: '', // 店铺名称
  contactNumber: '', // 联系电话
  bankAccount: '', // 银行卡号
  description: '' // 店铺描述（可选）
})

const formRules = {
  name: [
    { required: true, message: '请输入店铺名称' },
    { minLength: 2, maxLength: 50, message: '店铺名称长度应在2-50个字符之间' }
  ],
  contactNumber: [
    { required: true, message: '请输入店铺联系电话' },
    {
      validator: (value, callback) => {
        if (!/^1[3-9]\d{9}$/.test(value)) {
          callback('请输入正确的手机号')
        } else {
          callback()
        }
      }
    }
  ],
  bankAccount: [
    { required: true, message: '请输入店铺银行卡号' },
    {
      validator: (value, callback) => {
        if (!/^\d{16,19}$/.test(value)) {
          callback('请输入正确的银行卡号（16-19位数字）')
        } else {
          callback()
        }
      }
    }
  ],
  description: [
    { maxLength: 200, message: '店铺描述不能超过200个字符' }
  ]
}



const handleRegister = async () => {
  // 表单验证
  const validate = await registerFormRef.value.validate()
  if (validate) return

  try {
    loading.value = true
    
    // 构建提交数据，只包含实体类中的字段
    const submitData = {
      name: registerForm.name,
      contactNumber: registerForm.contactNumber,
      bankAccount: registerForm.bankAccount,
      description: registerForm.description || undefined
    }

    console.log('店铺注册信息:', submitData)
    
    // 这里应该调用实际的店铺注册API
    // const response = await shopAPI.register(submitData)
    
    Message.success('店铺注册成功！')
    router.push('/shop/login')
    
  } catch (err) {
    const message = err?.response?.data?.message ?? err.message ?? '注册失败，请重试'
    Message.error(message)
  } finally {
    loading.value = false
  }
}


</script>

<style scoped>
.shop-register-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #165dff 0%, #14c9c9 50%, #722ed1 100%);
  background-size: 400% 400%;
  animation: gradientBG 15s ease infinite;
  padding: 20px;
  position: relative;
  overflow: hidden;  width: 100vw; /* 使用视口宽度 */
}

@keyframes gradientBG {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

.register-wrapper {
  position: relative;
  z-index: 2;
  padding: 20px;
  width: 100%;
  max-width: none; /* 移除宽度限制 */
  display: flex;
  justify-content: center;
}

.register-card {
  width: 100%;
  max-width: 480px; 
  border-radius: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  overflow: hidden;
}

.register-header {
  text-align: center;
  padding: 40px 40px 20px;
}

.register-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
  background: linear-gradient(135deg, #165dff 0%, #14c9c9 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 20px rgba(22, 93, 255, 0.3);
}

.register-icon .icon {
  font-size: 40px;
  color: white;
}

.register-title {
  font-size: 32px;
  font-weight: 700;
  color: #1d2129;
  margin: 0 0 8px;
  background: linear-gradient(135deg, #165dff 0%, #14c9c9 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.register-subtitle {
  font-size: 16px;
  color: #86909c;
  margin: 0;
}

.required-hint {
  font-size: 14px;
  color: #86909c;
  margin-bottom: 20px;
  text-align: center;
}

.required-star {
  color: #f53f3f;
}

.input-section {
  margin-bottom: 24px;
}

.input-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 14px;
  color: #1d2129;
  font-weight: 500;
}

.input-label .arco-icon {
  color: #165dff;
  font-size: 16px;
}

:deep(.arco-input-wrapper) {
  border-radius: 12px;
  border: 2px solid #e5e6eb;
  transition: all 0.3s ease;
}

:deep(.arco-input-wrapper:hover) {
  border-color: #165dff;
}

:deep(.arco-input-wrapper:focus-within) {
  border-color: #165dff;
  box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.1);
}

:deep(.arco-textarea-wrapper) {
  border-radius: 12px;
  border: 2px solid #e5e6eb;
  transition: all 0.3s ease;
}

:deep(.arco-textarea-wrapper:hover) {
  border-color: #165dff;
}

:deep(.arco-textarea-wrapper:focus-within) {
  border-color: #165dff;
  box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.1);
}

.button-section {
  margin-top: 32px;
}

.register-button {
  width: 100%;
  height: 48px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  background: linear-gradient(135deg, #165dff 0%, #14c9c9 100%);
  border: none;
  box-shadow: 0 4px 12px rgba(22, 93, 255, 0.3);
  transition: all 0.3s ease;
}

.register-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(22, 93, 255, 0.4);
}

.register-button:active {
  transform: translateY(0);
}



.register-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.decoration-circle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  animation: float 6s ease-in-out infinite;
}

.circle-1 {
  width: 80px;
  height: 80px;
  top: 10%;
  left: 10%;
  animation-delay: 0s;
}

.circle-2 {
  width: 120px;
  height: 120px;
  top: 60%;
  right: 10%;
  animation-delay: 2s;
}

.circle-3 {
  width: 60px;
  height: 60px;
  bottom: 20%;
  left: 20%;
  animation-delay: 4s;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-20px);
  }
}



@media (max-width: 768px) {
  .register-card {
    margin: 20px;
  }
  
  .register-header {
    padding: 30px 20px 15px;
  }
  
  .register-form {
    padding: 0 20px 30px;
  }
  
  .register-title {
    font-size: 28px;
  }
}
</style>